package service;


import static org.junit.Assert.*;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;


import com.telkomsigma.hibernate.persistence.captain.entity.Captain;
import com.telkomsigma.hibernate.services.captain.CaptainService;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
@Transactional
public class TestCaptainService extends AbstractTransactionalJUnit4SpringContextTests{
	
	private Captain captain = new Captain();
	
	@Autowired
	private CaptainService captainService;	

	@Test
	public void testCheckDaoConfig() {				
		assertNotNull(captainService);		
	}


	@Test
	public void testInsertCaptain(){			
		captain.setPlayer_id("4");		
		captain.setTeam_id("1");
			
		Captain result = captainService.insert(captain);
		assertNotNull(result);
	}
	
	@Test
	public void testRemoveCaptain(){
		captain.setPlayer_id("4");
		boolean check = captainService.remove(captain);
		assertTrue(check==true);
	}
	
	@Test
	public void testFindByIdCaptain(){
		Captain result = captainService.findById("402880ea3192d999013192d99d150001");
		assertNotNull(result);
	}
	
	@Test
	public void testUpdate(){
	captain.setPlayer_id("1");
	captain.setTeam_id("2");
	Captain result = captainService.update(captain);
	assertNotNull(result);
	}
	
	@Test
	public void testFindAllCaptain(){		
		List<Captain> captainList = captainService.findAll(0,20);
		assertTrue(captainList.size()>0);		
	}
}
